package gen;

import java.io.IOException;
import java.util.Date;
import java.util.Calendar;
import java.io.DataOutputStream;
import java.io.ByteArrayOutputStream;



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author lchemina
 */

public class Ragot {

   private Integer numRagot;

   private String theTitre;
   private String theMessage;
   private String theAuteur;
   private Date theDate;


   public Ragot(String titre,String message,String auteur)
   {
       this.theTitre=titre;
       this.theAuteur=auteur;

       this.theMessage=message;
       this.theDate=new Date();

       this.numRagot= new Integer(message.hashCode());
   }

   public Ragot(String titre,String message,String auteur, Date date)
   {
       this.theTitre=titre;
       this.theAuteur=auteur;

       this.theMessage=message;
       this.theDate=date;

       //le hashcode n'est pas specifiable, il depend du message
       this.numRagot= new Integer(message.hashCode());
   }

   public String getTitre()
   {
     return this.theTitre;
   }

   public String getAuteur()
   {
     return this.theAuteur;
   }

   public String getMessage()
   {
     return this.theMessage;
   }


   public byte[] getBytes()
   {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        try {
            dos.writeUTF(theTitre);

            dos.writeUTF(this.theMessage);
            dos.writeUTF(this.theAuteur);
            dos.writeLong(this.theDate.getTime());

             } catch (IOException ex) {
            ex.printStackTrace();
        }
        

        return baos.toByteArray();
   }

  public long getLongDate()
  {
       return this.theDate.getTime();
  }

  public String getDate()
   {
        String resultat = "";
        Calendar c = Calendar.getInstance();
        c.setTime(this.theDate);


        switch(c.get(Calendar.DAY_OF_WEEK))
        {
            case Calendar.MONDAY:
              resultat += "Lundi";
            break;
            case Calendar.TUESDAY:
               resultat +="Mardi";
            break;
            case Calendar.WEDNESDAY:
               resultat +="Mercredi";
            break;
            case Calendar.THURSDAY:
               resultat +="Jeudi";
            break;
            case Calendar.FRIDAY:
               resultat +="Vendredi";
            break;
            case Calendar.SATURDAY:
               resultat +="Samedi";
            break;
            case Calendar.SUNDAY:
               resultat +="Dimanche";
            break;
        }

         resultat +=" ";
         resultat += c.get(Calendar.DATE);
         resultat +=" ";

    
         switch(c.get(Calendar.MONTH))
        {
            case Calendar.JANUARY:
              resultat += "Janvier";
            break;
            case Calendar.FEBRUARY:
               resultat +="Fevrier";
            break;
            case Calendar.MARCH:
               resultat +="Mars";
            break;
            case Calendar.APRIL:
               resultat +="Avril";
            break;
            case Calendar.MAY:
               resultat +="Mai";
            break;
            case Calendar.JUNE:
               resultat +="Juin";
            break;
            case Calendar.JULY:
               resultat +="Juillet";
            break;
             case Calendar.AUGUST:
               resultat +="Août";
            break;
            case Calendar.SEPTEMBER:
               resultat +="Septembre";
            break;
            case Calendar.OCTOBER:
               resultat +="Octobre";
            break;
            case Calendar.NOVEMBER:
               resultat +="Novembre";
            break;
            case Calendar.DECEMBER:
               resultat +="Décembre";
            break;
        }

        resultat +=" ";
        resultat += c.get(Calendar.YEAR);
        resultat +=" à ";
        resultat += c.get(Calendar.HOUR_OF_DAY);
        resultat +="h";
        resultat += c.get(Calendar.MINUTE);


        return resultat;
    }


  
}
